package com.web.util.rsaUtil;

/**
  * @Author: Mr.Yan
  * @create: 2019/3/25
  * @description: 测试json字符串验证
  */
public class RSATester {

    static String publicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCowwu8ftM+/PPlG5sNFjFtiNG4zsMCRTmfQuMXK6B6YV9Fs1k9a6z6sUVOsqvC2f3QecaOt2obNs8UdPw/EleOcYk/8Z7asVVJcARcYHiQ8NkBUmPyUQKAFiKjVvhtHpCfWZDfurHEQI/rE2mGCB9nMNJcvaSMjK/U0uyEMweqawIDAQAB";
    static String privateKey = "MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAKjDC7x+0z788+Ubmw0WMW2I0bjOwwJFOZ9C4xcroHphX0WzWT1rrPqxRU6yq8LZ/dB5xo63ahs2zxR0/D8SV45xiT/xntqxVUlwBFxgeJDw2QFSY/JRAoAWIqNW+G0ekJ9ZkN+6scRAj+sTaYYIH2cw0ly9pIyMr9TS7IQzB6prAgMBAAECgYEAmGZi/9sMC5LE8b4HPD8xbbgjpB/bzP4UtjTh/LeiGUI7licLTMMjF9TkQNhq8fCIHC8MVy9dO6w4P0IR1SdMNtfx674b3H6WjSpCXT9B4GVqzv6xiAh1r0wDoE7mJtLiAI5EkPxZm+IEim6D89mVn8/aUjkqkQ7ZLwAu2uvOHKkCQQDSm2rJP3o31pCpEGN2vJMg3Cy2R5woGUejmnnVM6ot8+up0L4z5Q9AmRaEXt1TGyateSt44/yGNEIsRiPYy90VAkEAzSLAwzU68awJmMwDznK44QMdIDGkIweLNJcRD5SO/ne4giQmYnDQTfB4Q48QIiYKp0RwJJRc7PTcxbVF7vJJfwJAWRo16KT5gUw+8bgkTKTlnl5ocEoFsBVZ8Ma3StNL6ZssFjFhdzUu6caa9y/ndXSkPXppQQE74k+Tu4WFPwCpLQJBALfFFXkLe8W7QFGxGwvcvIFfv7zym7+B55RybSdPCBcxe4qjBfwUYpggAC1Nwb9F4y9b4Tbz7pec+RbpQUBBr9MCQEGl3q9ZX/Qh7YFt9bVVHew/WAzJLapCdcrV3mgQQQFHaTvdEGtwYh4t/VwGVFNRHqCN5yS4LlD9YS5sGOf1U3s=";
/*  static {
        try {
            Map<String, Object> keyMap = RSAUtils.genKeyPair();
            publicKey = RSAUtils.getPublicKey(keyMap);
            privateKey = RSAUtils.getPrivateKey(keyMap);
            System.out.println("_____________公钥: \n\r" + publicKey);
            System.out.println("_____________私钥： \n\r" + privateKey);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }*/

    static long time = System.currentTimeMillis();
    static String jsonStr = "{" +
            "\"account\":\"mlqwsy123456\"," +
            "\"password\":3456 ," +
            "\"time\":\""+time+"\"}";

    public static void main(String[] args) throws Exception {
        test();

    }

    static void test() throws Exception {
        System.out.print("\n +++++++++++++++++++test test test test++++++++++++++++++公钥加密——私钥解密\n");
        System.out.println("\r加密前文字：\r\n" + jsonStr);

        String encodedData = RSAUtils.encryptedDataOnJava(jsonStr, publicKey);
        System.out.println("加密后文字：\r\n" + encodedData);

       // encodedData="k9wP67craCaWIrF0DjBS5WNV16LZckG1EWQKA6STpCYEhENhE/O1Ihs7F8Gzhnhpvt2PdFzyAXuSW/DKmB/6Tra5pChoVgsSneBmQrmtqlM/LhgmH07Q04T/Eo87CYWdP1DIUnQz8up7A7+HPELGk1IxO3icn+JB0QL9qxUsYcIQsGkSG5TcT8CIuXJLRWIOi4XUXN9ffrUEzvO0HI6gf02zW7bZHjGpkgHrjSDV/RsA+uuShdEruUnOazEbIjkLtCRGGlCyz9lLuwZWfr2jOocZDKi8f9B1KXq36EiWWAWfLAoJ0yGZ69djuadKHVrnENnbNYXF6Cj9GS3EcNgZAg==";
        String decodedData = RSAUtils.decryptDataOnJava(encodedData, privateKey);
        System.out.println("解密后文字: \r\n" + decodedData);
    }




}